define(["jquery","matchMedia",'jquery-ui-modules/widget'],function($,mediaCheck){"use strict";$.widget('mage.stickyElement',{options:{activeClass:'sticky',bodyClass:'element-sticky-active',delay:0,stickDelay:0,fadeIn:300,stickyContainerSelector:false,mobileStick:true,mobileStickOnEnd:true,mobileStickOffset:0,mobileOffsetTopSelector:false,mobileSetTopFromSelector:false,desktopStick:true,desktopStickOnEnd:true,desktopStickOffset:0,desktopOffsetTopSelector:false,desktopSetTopFromSelector:false,onStickCallback:false,onResetCallback:false,stickOnInit:true,stickOnScrollUp:false},offsetTop:null,lastScrollPosition:0,currentScrollPosition:0,stickyContainer:[],body:[],isActive:false,desktopViewportActive:false,stickTimeout:null,document:null,_create:function(){this.stickyContainer=$(this.options.stickyContainerSelector);if(!this.stickyContainer.length){this.stickyContainer=this.element.parent();} this.body=$('body');this.document=$(document);this.desktopViewportActive=matchMedia("screen and (min-width:768px)").matches $(window).on({'scroll':$.proxy(this._onScroll,this),'resize':$.proxy(this._stickResizeTrigger,this)});this._checkMq();if(this.options.stickOnInit){this._stick();}},_onScroll:function(){this.currentScrollPosition=this.document.scrollTop();this._stick();this.lastScrollPosition=this.currentScrollPosition;},_getOffsetTop:function(){let offsetTop=null;let offsetTopElement=this.element;this.reset();if(this.desktopViewportActive){if(this.options.desktopStick){offsetTop=0;if(this.options.desktopStickOnEnd){if(this.options.desktopOffsetTopSelector&&$(this.options.desktopOffsetTopSelector).length){offsetTopElement=$(this.options.desktopOffsetTopSelector);}} offsetTop+=offsetTopElement.offset().top if(this.options.desktopStickOnEnd){offsetTop+=offsetTopElement.innerHeight();} if(this.options.desktopStickOffset){offsetTop+=parseFloat(this.options.desktopStickOffset)} this.offsetTop=offsetTop;}}else{if(this.options.mobileStick){offsetTop=0;if(this.options.mobileStickOnEnd){if(this.options.mobileOffsetTopSelector&&$(this.options.mobileOffsetTopSelector).length){offsetTopElement=$(this.options.mobileOffsetTopSelector);}} offsetTop+=offsetTopElement.offset().top if(this.options.mobileStickOnEnd){offsetTop+=offsetTopElement.innerHeight();} if(this.options.mobileStickOffset){offsetTop+=parseFloat(this.options.mobileStickOffset)} this.offsetTop=offsetTop;}} this.offsetTop=offsetTop;},_checkMq:function(){var $this=this;mediaCheck({media:'(min-width: 768px)',entry:function(){$this.desktopViewportActive=true;$this.reset();$this._stickResizeTrigger();},exit:function(){$this.desktopViewportActive=false;$this.reset();$this._stickResizeTrigger();}});},_stick:function(){if(this.offsetTop===null){this._getOffsetTop();} this.currentOffsetTop=this.document.scrollTop();if(this._checkRequireStick()){if(!this.isActive){this.stickyContainer.height(this.stickyContainer.innerHeight());if(this.desktopViewportActive){if(this.options.fadeIn){this.element.hide();} this.body.addClass(this.options.bodyClass);this.stickyContainer.addClass(this.options.activeClass);this.element.addClass(this.options.activeClass);if(this.options.desktopSetTopFromSelector){let posElement=$(this.options.desktopSetTopFromSelector).first();if(posElement.length){this.element.css('top',posElement.position().top+posElement.innerHeight())}} if(this.options.fadeIn){this.element.fadeIn(this.options.fadeIn);}}else{this.body.addClass(this.options.bodyClass);this.stickyContainer.addClass(this.options.activeClass);this.element.addClass(this.options.activeClass);if(this.options.mobileSetTopFromSelector){let posElement=$(this.options.mobileSetTopFromSelector).first();if(posElement.length){this.element.css('top',posElement.position().top+posElement.innerHeight())}}} this.isActive=true;if(typeof this.options.onStickCallback=='function'){this.options.onStickCallback.bind(this)();}}}else{if(this.isActive){this.reset();}}},_checkRequireStick:function(){return this.offsetTop!==null&&this.currentOffsetTop>this.offsetTop&&(!this.options.stickOnScrollUp||this.currentScrollPosition